package org.jeecgframework.web.system.util;

import org.jeecgframework.core.util.ApplicationContextUtil;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.web.system.service.SystemService;

import java.util.List;
import java.util.Map;

/**
 * User: MaCiCi
 * Date: 13-7-26
 * Time: 下午2:07
 */
public class wmUtil {

    



    /**
     * 删除指定文件夹下所有文件
     * @param path 文件夹完整绝对路径
     * @return
     */
    public static boolean checkstcok(String binid,String tinid,String goodsid,String prodate,String basecount) {
        boolean flag = false;
        try {
			String goods = null;
			if(!StringUtil.isEmpty(goodsid)){
				if(goodsid.endsWith("l")){
					goods = goodsid.substring(0,goodsid.length() - 1);
					System.out.print("11111111I"+goods);
				}else{
					goods = goodsid;
					System.out.print("22222"+goods);

				}

			}
			SystemService systemService =ApplicationContextUtil.getContext().getBean(SystemService.class);
			String  tsql = "select ws.base_unit,ws.zhong_wen_qch, ws.ku_wei_bian_ma,ws.bin_id,ws.shp_ming_cheng,cast(sum(ws.base_goodscount) as signed) as goods_qua, mb.qu_huo_ci_xu, ws.goods_pro_data"
					+ "  from wv_stock ws, md_bin mb  where "
					+ "   ws.ku_wei_bian_ma = mb.ku_wei_bian_ma and mb.ting_yong <> 'Y' and (ws.kuctype = '库存' or ws.kuctype = '待下架')"
					+ "   and ws.ku_wei_bian_ma = ? "
					+ "   and ws.bin_id =  ? "
					+ "   and ws.goods_id =  ? "
					+ "   and ws.goods_pro_data =  ? "
					+ "   group by ws.ku_wei_bian_ma,ws.bin_id,ws.goods_id,mb.qu_huo_ci_xu, ws.goods_pro_data order by ws.goods_pro_data , ws.goods_qua ,mb.qu_huo_ci_xu,ws.create_date desc";

			List<Map<String, Object>> result=  systemService.findForJdbc(tsql, binid,tinid,goods,prodate);
			if(result.size() > 0) {
				if(Long.parseLong(result.get(0).get("goods_qua").toString())>=Long.parseLong(basecount)){
					flag = true;
				}

			}
		}catch (Exception e){

		}

       return flag;
    }
    
    public static boolean checkstcoka(String binid,String tinid,String goodsid,String prodate,String basecount) {
        boolean flag = false;
		try {
			String goods = null;
			if (!StringUtil.isEmpty(goodsid)) {
				if (goodsid.endsWith("l")) {
					goods = goodsid.substring(0, goodsid.length() - 1);
					System.out.print("11111111I" + goods);
				} else {
					goods = goodsid;
					System.out.print("22222" + goods);

				}

			}
			SystemService systemService = ApplicationContextUtil.getContext().getBean(SystemService.class);
			String tsql = "select ws.base_unit,ws.zhong_wen_qch, ws.ku_wei_bian_ma,ws.bin_id,ws.shp_ming_cheng,cast(sum(ws.base_goodscount) as signed) as goods_qua, mb.qu_huo_ci_xu, ws.goods_pro_data"
					+ "  from wv_stock ws, md_bin mb  where "
					+ "   ws.ku_wei_bian_ma = mb.ku_wei_bian_ma and mb.ting_yong <> 'Y' and (ws.kuctype = '库存' )"
					+ "   and ws.ku_wei_bian_ma = ? "
					+ "   and ws.bin_id =  ? "
					+ "   and ws.goods_id =  ? "
					+ "   and ws.goods_pro_data =  ? "
					+ "   group by ws.ku_wei_bian_ma,ws.bin_id,ws.goods_id,mb.qu_huo_ci_xu, ws.goods_pro_data order by ws.goods_pro_data , ws.goods_qua ,mb.qu_huo_ci_xu,ws.create_date desc";

			List<Map<String, Object>> result = systemService.findForJdbc(tsql, binid, tinid, goods, prodate);
			if (result.size() > 0) {
				if (Long.parseLong(result.get(0).get("goods_qua").toString()) >= Long.parseLong(basecount)) {
					flag = true;
				}

			}
		}catch (Exception e){

		}
       return flag;
    }
    
}
